package org.elanfox.intellicommunity.common.base;

import lombok.Getter;
import lombok.Setter;

/**
 * Created by allan on 25/12/2017.
 */
@Setter
@Getter
public class ApiResult<T> {
    private int resultCode;
    private String resultMsg;
    private T data;

    public static ApiResult<Void> success() {
        ApiResult<Void> apiResult = new ApiResult<>();
        apiResult.resultCode = ResultCodeEnum.SUCCESS.getResultCode();
        apiResult.resultMsg = ResultCodeEnum.SUCCESS.getResultMsg();
        return apiResult;
    }

    public static <T> ApiResult<T> success(T obj) {
        ApiResult<T> apiResult = new ApiResult<>();
        apiResult.resultCode = ResultCodeEnum.SUCCESS.getResultCode();
        apiResult.resultMsg = ResultCodeEnum.SUCCESS.getResultMsg();
        return apiResult;
    }

    public static ApiResult resultWith(ResultCodeEnum resultCode, Object data) {
        ApiResult apiResult = new ApiResult();
        apiResult.resultCode = resultCode.getResultCode();
        apiResult.resultMsg = resultCode.getResultMsg();
        apiResult.data = data;
        return apiResult;
    }

    public static ApiResult resultWith(ResultCodeEnum resultCode) {
        ApiResult apiResult = new ApiResult();
        apiResult.resultCode = resultCode.getResultCode();
        apiResult.resultMsg = resultCode.getResultMsg();
        return apiResult;
    }

    public static ApiResult resultWith(ResultCodeEnum resultCode, String msg, Object data) {
        ApiResult apiResult = new ApiResult();
        apiResult.resultCode = resultCode.getResultCode();
        apiResult.resultMsg = msg;
        apiResult.data = data;
        return apiResult;
    }

    public static ApiResult errorWith(ResultCodeEnum resultCode) {
        ApiResult apiResult = new ApiResult();
        apiResult.resultCode = resultCode.getResultCode();
        apiResult.resultMsg = resultCode.getResultMsg();
        return apiResult;
    }

    public static ApiResult errorWith(ResultCodeEnum resultCode, String msg) {
        ApiResult apiResult = new ApiResult();
        apiResult.resultCode = resultCode.getResultCode();
        apiResult.resultMsg = msg;
        return apiResult;
    }

    public static void main(String[] args) {
        System.out.println("70efdf2ec9b086079795c442636b55fb".length());
        System.out.println("20d52758ac31635e9f664e28e5d5138c".length());
    }
}
